{layout name="layout" /}

<fieldset class="layui-elem-field">
    <legend>基础控制器</legend>
    <div class="layui-field-box">
        1、选择模块<br>
        2、模型取至数据层模型 -- model文件夹,如果选择的是<span style="color: red;">服务层或逻辑层，请确保逻辑层、服务层有对应的文件</span><br><br>
        3、如果控制器需要使用中间件<span style="color: red;">请确保http/middleware文件中，有中间件文件</span><br><br>
        4、<span style="color: red;">资源控制器无需填写，控制器方法名前缀</span><br><br>
    </div>
</fieldset>
<form  class="layui-form" action="{:url('create_controller')}" method="get">
    <input type="hidden" name="resources" id="resources" />
    <div class="layui-form-item" style="width: 30%;">
        <label class="layui-form-label">控制器名字</label>
        <div class="layui-input-block">
            <input type="text" name="controller_name" class="layui-input">
            <span style="color: red;">必填</span>
        </div>
    </div>
    <div class="layui-form-item" style="width: 30%;">
        <label class="layui-form-label">控制器方法名前缀</label>
        <div class="layui-input-block">
            <input type="text" name="function_name" class="layui-input">
            <span style="color: red;">未填写，方法名前缀默认为控制器名字</span>
        </div>
    </div>
    <div class="layui-form-item" style="width: 30%;">
        <label class="layui-form-label">选择模块：</label>
        <div class="layui-input-block">
            <select name="mokuai" lay-filter="mokuai">
                <option value="">选择模块</option>
                {volist name="mokuai" id="vo"}
                <option value="{$vo}">{$vo}</option>
                {/volist}
            </select>
            <span style="color: red;">未选择,控制器命名默认为index</span>
        </div>
    </div>
    <div class="layui-form-item layui-hide" id="selectmodel" style="width: 30%;">
        <label class="layui-form-label">选择要调用分层：</label>
        <div class="layui-input-block">
            <select name="logic" lay-filter="logic" id="logic">
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit >生成控制器文件</button>
            <button class="layui-btn layui-btn-warm" lay-submit lay-filter="resources">生成资源控制器文件</button>
        </div>
    </div>
</form>
<script type="text/javascript">
    layui.use('form', function(){
        var form = layui.form;
        //监听提交按钮
        form.on('submit(resources)', function(data){
            $("#resources").val(1);
            return true;
        });
        //监听下拉选择
        form.on('select(mokuai)', function(data){
            if(data.value == ''){
                return;
            }
            $.ajax({
                type: 'post',
                url: 'controller_step2',
                data: {mokuai:data.value,auth:1},
                success: function (res) {
                    $("#logic").empty();
                    $("#logic").append("<option>选择模型</option>");
                    $.each(res.logic,function(n,value){
                        $("#logic").append("<option value="+value+">"+value+"</option>");
                    });
                    $("#selectmodel").removeClass('layui-hide');
                    form.render('select');
                }
            });
        });
    });
</script>
